package com.kfm.jdbc.day0328;

import com.kfm.jdbc.day0327.entity.Account;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Test03 {

    public static void main(String[] args) {
        DBUtils<Account> dbUtils = new DBUtils<>(5);

        Connection connection = dbUtils.getConnection();

        PreparedStatement preparedStatement = null;
        try {
            preparedStatement = connection.prepareStatement("select * from account where id = ?");
            preparedStatement.setObject(1, 1);

            ResultSet resultSet = preparedStatement.executeQuery();

            if (resultSet.next()){
                System.out.println(resultSet.getObject(2));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

//        List<Connection> list = new ArrayList<>();
//        Connection connection = null;
//        for (int i = 0; i < 10; i++) {
//            connection = dbUtils.getConnection();
//            System.out.println(connection);
//
//            list.add(connection);
//        }
//
//        for (Connection connection1 : list){
//            try {
//                connection1.close();
//            } catch (SQLException e) {
//                throw new RuntimeException(e);
//            }
//        }

    }
}
